package com.leyou.page.controller;

import com.leyou.page.service.FileService;
import com.leyou.page.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Map;

/**
 * @author 岩冰
 * @version 1.0
 * @date:2018/10/13
 */
@Controller
@RequestMapping("item")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private FileService fileService;
    @GetMapping("{id}.html")
    public String toItemPage(@PathVariable("id")Long id, Model model) throws Exception {
        Map<String, Object> map = goodsService.loadModel(id);
        model.addAllAttributes(map);
        if (!this.fileService.exists(id)) {
            this.fileService.createHtml(id);
        }
        return "item";
    }



}
